use tracing::info;

use bc_base::{
    self, PrivateKeyBytes, PublicKeyBytes, PublicKeyHashBytes, TransactionValue,
    wallet::ItemNumberInWalletDb,
};

use crate::{BcManager, BcManagerError};

impl BcManager {
    pub async fn dump_wallet_account(&self) {
        let wallet = self.wallet.lock().await;
        wallet.dump_wallet_account();
    }

    pub async fn wallet_item_number(&self) -> ItemNumberInWalletDb {
        self.wallet.lock().await.get_item_number().await
    }

    pub async fn clear_utxos_in_wallet(&self) {
        // let mut wallet = self.wallet.lock().await;
        // wallet.clear_utxos().await.unwrap();
    }

    pub async fn query_balance(&self) -> TransactionValue {
        let account_manager = self.wallet.lock().await;
        account_manager.get_balance().await
    }

    pub async fn create_keypair(&self) -> Result<PublicKeyHashBytes, BcManagerError> {
        println!("Creating keypair");
        let mut wallet = self.wallet.lock().await;
        let pub_hash_key = wallet.create_account().await?;
        Ok(pub_hash_key)
    }

    pub async fn add_keypair(
        &self,
        public_key: &PublicKeyBytes,
        private_key: &PrivateKeyBytes,
    ) -> Result<(), BcManagerError> {
        info!("Adding keypair");
        let mut wallet = self.wallet.lock().await;
        wallet.add_account(public_key, private_key).await?;
        Ok(())
    }
}
